Thread: [question] ifstream read file, thanks!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    Cool [close] ifstream read file, thanks!

    ---------------------------------------------
    My config.ini content:
    c:\program\edit plus\editplus.exe
    ---------------------------------------------

    Abnormal Output: c:\program\editplus\editplus.exe [the blank missed between edit AND plus?]
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    void main() //the program starts here
    {
    	
    	ifstream OpenFile("config.ini");
    	char ch[80];
                    int i;
    	while(!OpenFile.eof())
    	{
    	OpenFile >> ch;
    	cout << ch;
    	}
    	cout << endl;
    	OpenFile.close();
    
    	cin >> i; 
    }

    Abnormal output: c:\program\edit plus\editplus.exee (double e)
    Why ?
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    void main() //the program starts here
    {
    	
    	ifstream OpenFile("config.ini");
    	char ch;
    	int i;
    	while(!OpenFile.eof())
    	{
    	 OpenFile.get(ch);
    	 cout << ch;
    	}
    	cout << endl;
    	OpenFile.close();
    
    	cin >> i; 
    }
    Last edited by userpingz; 05-19-2009 at 05:34 AM. Reason: better style for reading,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. How to convert char read from file into string
    By cruxxe in forum C Programming
    Replies: 7
    Last Post: 05-22-2002, 02:09 PM
  4. cannot read long file name
    By calvinlkn in forum C Programming
    Replies: 5
    Last Post: 04-11-2002, 05:04 AM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM

Tags for this Thread